home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / etc / init.d / rsync < prev    next >
Text File  |  2008-07-28  |  5KB  |  157 lines

  1. #! /bin/sh
  2.  
  3. ### BEGIN INIT INFO
  4. # Provides:          rsyncd
  5. # Required-Start:    $remote_fs $syslog
  6. # Required-Stop:     $remote_fs $syslog
  7. # Should-Start:      $named
  8. # Default-Start:     2 3 4 5
  9. # Default-Stop:      1
  10. # Short-Description: fast remote file copy program daemon
  11. # Description:       rsync is a program that allows files to be copied to and
  12. #                    from remote machines in much the same way as rcp.
  13. #                    This provides rsyncd daemon functionality.
  14. ### END INIT INFO
  15.  
  16. set -e
  17.  
  18. # /etc/init.d/rsync: start and stop the rsync daemon
  19.  
  20. DAEMON=/usr/bin/rsync
  21. RSYNC_ENABLE=false
  22. RSYNC_OPTS=''
  23. RSYNC_DEFAULTS_FILE=/etc/default/rsync
  24. RSYNC_CONFIG_FILE=/etc/rsyncd.conf
  25. RSYNC_NICE_PARM=''
  26.  
  27. test -x $DAEMON || exit 0
  28.  
  29. . /lib/lsb/init-functions
  30. . /etc/default/rcS
  31.  
  32. if [ -s $RSYNC_DEFAULTS_FILE ]; then
  33.     . $RSYNC_DEFAULTS_FILE
  34.     case "x$RSYNC_ENABLE" in
  35.         xtrue|xfalse)   ;;
  36.         xinetd)         exit 0
  37.                         ;;
  38.         *)              log_failure_msg "Value of RSYNC_ENABLE in $RSYNC_DEFAULTS_FILE must be either 'true' or 'false';"
  39.                         log_failure_msg "not starting rsync daemon."
  40.                         exit 1
  41.                         ;;
  42.     esac
  43.     case "x$RSYNC_NICE" in
  44.         x[0-9])         RSYNC_NICE_PARM="--nicelevel $RSYNC_NICE";;
  45.         x[1-9][0-9])    RSYNC_NICE_PARM="--nicelevel $RSYNC_NICE";;
  46.         x)              ;;
  47.         *)              log_warning_msg "Value of RSYNC_NICE in $RSYNC_DEFAULTS_FILE must be a value between 0 and 19 (inclusive);"
  48.                         log_warning_msg "ignoring RSYNC_NICE now."
  49.                         ;;
  50.     esac
  51. fi
  52.  
  53. export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
  54.  
  55. case "$1" in
  56.   start)
  57.     if "$RSYNC_ENABLE"; then
  58.             log_daemon_msg "Starting rsync daemon" "rsync"
  59.         if [ -s /var/run/rsync.pid ] && kill -0 $(cat /var/run/rsync.pid) >/dev/null 2>&1; then
  60.                 log_progress_msg "apparently already running"
  61.                 log_end_msg 0
  62.         exit 0
  63.         fi
  64.             if [ ! -s "$RSYNC_CONFIG_FILE" ]; then
  65.                 log_failure_msg "missing or empty config file $RSYNC_CONFIG_FILE"
  66.         log_end_msg 1
  67.                 exit 1
  68.             fi
  69.             if start-stop-daemon --start --quiet --background \
  70.                 --pidfile /var/run/rsync.pid --make-pidfile \
  71.                 $RSYNC_NICE_PARM --exec /usr/bin/rsync \
  72.                 -- --no-detach --daemon --config "$RSYNC_CONFIG_FILE" $RSYNC_OPTS
  73.             then
  74.                 rc=0
  75.                 sleep 1
  76.                 if ! kill -0 $(cat /var/run/rsync.pid) >/dev/null 2>&1; then
  77.                     log_failure_msg "rsync daemon failed to start"
  78.                     rc=1
  79.                 fi
  80.             else
  81.                 rc=1
  82.             fi
  83.             if [ $rc -eq 0 ]; then
  84.                 log_end_msg 0
  85.             else
  86.                 log_end_msg 1
  87.                 rm -f /var/run/rsync.pid
  88.             fi
  89.         else
  90.             if [ -s "$RSYNC_CONFIG_FILE" ]; then
  91.         [ "$VERBOSE" != no ] && log_warning_msg "rsync daemon not enabled in /etc/default/rsync, not starting..."
  92.             fi
  93.         fi
  94.     ;;
  95.   stop)
  96.         log_daemon_msg "Stopping rsync daemon" "rsync"
  97.     start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/rsync.pid
  98.         log_end_msg $?
  99.     rm -f /var/run/rsync.pid
  100.     ;;
  101.  
  102.   reload|force-reload)
  103.         log_warning_msg "Reloading rsync daemon: not needed, as the daemon"
  104.         log_warning_msg "re-reads the config file whenever a client connects."
  105.     ;;
  106.  
  107.   restart)
  108.     set +e
  109.         if $RSYNC_ENABLE; then
  110.             log_daemon_msg "Restarting rsync daemon" "rsync"
  111.         if [ -s /var/run/rsync.pid ] && kill -0 $(cat /var/run/rsync.pid) >/dev/null 2>&1; then
  112.         start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/rsync.pid || true
  113.         sleep 1
  114.         else
  115.                 log_warning_msg "rsync daemon not running, attempting to start."
  116.             rm -f /var/run/rsync.pid
  117.         fi
  118.             if [ ! -s "$RSYNC_CONFIG_FILE" ]; then
  119.                 log_failure_msg "missing or empty config file $RSYNC_CONFIG_FILE"
  120.         log_end_msg 1
  121.                 exit 1
  122.             fi
  123.             if start-stop-daemon --start --quiet --background \
  124.                 --pidfile /var/run/rsync.pid --make-pidfile \
  125.                 $RSYNC_NICE_PARM --exec /usr/bin/rsync \
  126.                 -- --no-detach --daemon --config "$RSYNC_CONFIG_FILE" $RSYNC_OPTS
  127.             then
  128.                 rc=0
  129.                 sleep 1
  130.                 if ! kill -0 $(cat /var/run/rsync.pid) >/dev/null 2>&1; then
  131.                     log_failure_msg "rsync daemon failed to start"
  132.                     rc=1
  133.                 fi
  134.             else
  135.                 rc=1
  136.             fi
  137.             if [ $rc -eq 0 ]; then
  138.                 log_end_msg 0
  139.             else
  140.                 log_end_msg 1
  141.                 rm -f /var/run/rsync.pid
  142.             fi
  143.         else
  144.             [ "$VERBOSE" != no ] && log_warning_msg "rsync daemon not enabled in /etc/default/rsync, not starting..."
  145.         fi
  146.     ;;
  147.   status)
  148.     status_of_proc -p /var/run/rsync.pid "$DAEMON" rsync && exit 0 || exit $?
  149.     ;;
  150.  
  151.   *)
  152.     echo "Usage: /etc/init.d/rsync {start|stop|reload|force-reload|restart|status}"
  153.     exit 1
  154. esac
  155.  
  156. exit 0
  157.